package com.luzhikun.JSON.servlet;

import com.luzhikun.JSON.model.Student;
import com.luzhikun.JSON.util.JSONUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
/*
 * @Author liu-miss
 * @Description 传递数据到客户端，通过JSON实现数据传递
 * @Date 19:12 2021/5/8
 **/
@WebServlet(name = "StudentServlet", value = "/StudentServlet")
public class StudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 创建学生对象
        Student st=new Student("吴杰",12);
        // 将学生对象放入请求域中
        request.setAttribute("key",new JSONUtil().jsonObject(st));
        // 请求转发
        request.getRequestDispatcher("/commnutie.jsp").forward(request,response);


    }

}
